/**
 * Created by Administrator on 2018/3/30 0030.
 */
const mysql = require('mysql')
const config = require('../config/default.config')
const pool = mysql.createPool({
    host: config.database.host,
    port: config.database.port,
    password: config.database.password,
    user: config.database.username,
    database: config.database.database
})
let query = async (sql, valus) => {
    return new Promise((resolve, reject) => {
        pool.getConnection((err, connection) => {
            if (err) {
                resolve(err)
            } else {
                connection.query(sql, valus, (err, rows) => {
                    if (err) {
                        reject(err)
                    } else {
                        resolve(rows)
                    }
                    connection.release()
                })
            }
        })
    })
}
const sqlLite = {}
sqlLite.insertUser = (value) => {
    let _sql = `insert into users(name,password) values(?,?);`
    return query(_sql, value)
}
sqlLite.selectUser = () => {
    let _sql = `select * from users;`
    return query(_sql)
}
sqlLite.findByName = (name)=>{
    let _sql = `select * from users where name="${name}";`
    return query(_sql,name)
}
sqlLite.addUserInfo = (value)=>{
    let _ssql = `insert in user_info values`
}
module.exports = sqlLite;